<template>
  <Model
    :title="row.edit ? '编辑' : '添加'"
    :width="800"
    :show="show"
    @confirm="confirm"
    @cancel="cancel"
  >
    <Form slot="form">
      <FormDoubleItem :labels="['参赛名称', '参赛项目名称']">
        <a-input
          slot="left"
          v-model="row.name"
          placeholder="请输入内容"
        ></a-input>
        <a-select
          slot="right"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.matchname"
          @change="(e) => changeValue(e, 'matchname')"
        >
          <a-select-option
            v-for="item in System"
            :key="item.id"
            :value="item.name"
          >
            {{ item.name }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['项目负责人', '负责人id']">
        <a-input
          slot="left"
          v-model="row.leader"
          placeholder="请输入内容"
        ></a-input>
        <a-input
          slot="right"
          v-model="row.studentId"
          placeholder="请输入内容"
        ></a-input>
      </FormDoubleItem>
      <FormDoubleItem :labels="['指导老师', '年度']">
        <a-input
          slot="left"
          v-model="row.teacher"
          placeholder="请输入内容"
        ></a-input>
        <a-input
          slot="right"
          v-model="row.year"
          placeholder="请输入内容"
        ></a-input>
      </FormDoubleItem>
      <FormDoubleItem :labels="['级别', '状态']">
        <a-select
          slot="left"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.level"
          @change="(e) => changeValue(e, 'level')"
        >
          <a-select-option v-for="item in level" :key="item" :value="item">
            {{ item }}
          </a-select-option>
        </a-select>
        <a-select
          slot="right"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.status"
          @change="(e) => changeValue(e, 'status')"
        >
          <a-select-option value="1">进行中</a-select-option>
          <a-select-option value="0">结束</a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['项目成员', '审核']">
        <a-input
          slot="left"
          v-model="row.members"
          placeholder="请输入内容"
        ></a-input>
        <a-select
          slot="right"
          show-search
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          :default-value="row.check"
          @change="(e) => changeValue(e, 'check')"
        >
          <a-select-option v-for="item in check" :key="item" :value="item">
            {{ item }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['获奖情况', '附件文件']">
        <a-input
          slot="left"
          v-model="row.situation"
          placeholder="请输入内容"
        ></a-input>
        <a-upload
          slot="right"
          :file-list="fileList"
          :multiple="false"
          :remove="handleRemove"
          :before-upload="beforeUpload"
        >
          <a-button> <a-icon type="upload" /> 选择文件 </a-button>
        </a-upload>
      </FormDoubleItem>
    </Form>
  </Model>
</template>

<script>
import Model from "components/common/model/Model";
import Form from "components/common/form/Form";
import FormItem from "components/common/form/formItem/FormItem";
import FormLenItem from "components/common/form/formItem/FormLenItem";
import FormDoubleItem from "components/common/form/formDoubleItem/FormDoubleItem";
import FormAlignItem from "components/common/form/formAlignItem/FormAlignItem";
import { check, teacherProjectStatus, level, years } from "@/assets/data/other";
// import {years} from '@/assets/data/other';
import { hasPropertyEmpty } from "common/index";
import { getSystem } from "@/network/Info/BaseInfo";

export default {
  components: {
    Model,
    Form,
    FormDoubleItem,
  },
  props: {
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    show: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {
      check,
      teacherProjectStatus,
      level,
      years,
      fileList: [],
      System: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    async init() {
      const aystem = await getSystem();
      this.System = aystem.data[3].data;
      console.log(aystem);
    },
    beforeUpload(file) {
      this.fileList = [file];
      this.row.file = file;
      return false;
    },
    handleRemove(file) {
      const index = this.fileList.indexOf(file);
      const newFileList = this.fileList.slice();
      newFileList.splice(index, 1);
      this.fileList = newFileList;
      this.row.file = "";
    },

    changeValue(value, key) {
      this.row[key] = value;
      console.log(this.row[key]);
    },

    confirm() {
      const row = this.row;
      console.log(row.level);
      row.level = level.indexOf(row.level);

      row.check = check.indexOf(row.check);

      this.System.forEach((item) => {
        if (item.name === row.matchname) {
          row.matchname = item.id;
        }
      });
      console.log(row.matchname);

      this.$emit("confirm", {
        ...row,
      });
    },
    cancel() {
      this.$emit("cancel");
    },
  },
};
</script>

<style lang="less" scoped>
.t-form {
  text-align: center;
  display: flex;
  flex-direction: column;
  justify-items: center;
  padding-right: 30px;
  .ant-btn {
    width: 145.5px !important;
  }
}
</style>